<template>
	<view>
		<image src="https://yunkeososyunchuc.bc8t.cn/lianaikongjian/static/yun1.png" style="width: 50%; position: fixed; z-index: 1; top: 0; left: 0; " mode="widthFix"></image>
		<image src="https://yunkeososyunchuc.bc8t.cn/lianaikongjian/static/yun2.png" style="width: 50%; position: fixed; z-index: 1; top: 0; right: 0; " mode="widthFix"></image>
		<image src="https://yunkeososyunchuc.bc8t.cn/lianaikongjian/static/bottom.png" mode="widthFix" style="width: 100%; position: fixed; z-index: 1; bottom: 0; right: 0; "></image>
		<!-- <view style="font-size: 20px; color:#fff; font-size: 30px; font-weight: bold; text-align: center; line-height: 200px; " >
			{{item.describe}}
		</view> -->
		<view>
			<view class="flex a-t">
				<view v-for="(item, index) in 1" class="" style="width: 80%;margin:40px auto;"><image style="width:100%;" src="https://yunkeososyunchuc.bc8t.cn/lianaikongjian/static/kuang.png" mode="widthFix"></image></view>
			</view>
		</view>
		<view
			@click="kongjian"
			style="position: fixed;z-index:4;width: 50px;height: 50px;background: rgba(0,0,0,0.5);border-radius: 50%;text-align:center;line-height: 50px;color: #fff;line-height: 50px;right: 20px;bottom: 100px;"
		>
			刷新
		</view>
		<!-- <image @click="gourl()" src="https://yunkeososyunchuc.bc8t.cn/lianaikongjian/static/button.png" style="width: 50%; position: fixed; z-index: 1; bottom: 80px; left: 50%; margin-left: -25%;  " mode="widthFix"></image> -->
		<view style="text-align: center;color: #fff;width: 240px;margin: auto;">
			<view><u-button @click="gourl()" style="width:240px;" type="warning" shape="circle">生成虚拟空间</u-button></view>
			<view style="margin-top: 40px;">
				<!-- 邀请好友 -->
				<u-button open-type="share" style="width:240px;" type="success" shape="circle">邀请好友</u-button>
			</view>

			<!-- <image :src="url" style="width: 14px; margin-left: 6px; " mode="widthFix"></image> -->
			<!-- <image :src='url' mode="" style="width: 70px;height: 70px;"></image> -->
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			item: {},
			num: -1,
			istrue: false,
			my_space_id: '',
			sex: '',
			type: ''
		};
	},
	onLoad(e) {
		this.item = JSON.parse(e.item);
		this.sex = e.sex;
		if (e.type) {
			this.type = e.type;
		}
		this.create('normal');
	},
	onShareAppMessage(res) {
	    if(!this.my_space_id){
            uni.showToast({
                title: '获取空间信息失败，请返回重试！',
                icon: 'none',
                duration: 2000
            });
            setTimeout(function () {
                uni.navigateTo({
                    url: '/pages/index/index'
                });
            }, 2000);
		}

		return {
			title: '来和我一起开通吧',
			path: '/pages/kongjian/kongjian?my_space_id=' + this.my_space_id
		};
	},
	methods: {
		kongjian() {
			this.getmy_space(true);
		},
		async getmy_space(refresh = false) {
			let res = await this.$u.api.my_space({ is_refresh: refresh });
			if (res.length > 0) {
				uni.switchTab({
					url: '/pages/content/content'
				});
			}
		},
		gourl() {
			this.create('temp');
		},
		create(e) {
			return new Promise((r, n) => {
				uni.setStorageSync('sex', this.sex);
				let data = {
					space_id: this.item.id,
					sex: this.sex,
					type: e
				};
				this.$u.api.create(data).then(res => {
                    if (e == 'temp') {
						uni.navigateTo({
							url: '/pages/content/content'
						});
					} else {
						this.my_space_id = res.id;
						// r(res.id);
					}
				}).catch(function (res) {
                    uni.showToast({
                        title: res.msg,
                        icon: 'none',
                        duration: 2000
                    });
                    setTimeout(function () {
                        uni.navigateTo({
                            url: '/pages/index/index'
                        });
                    }, 2000);
                });
			});
		}
	}
};
</script>

<style>
page {
	background: #fec5ce;
}
</style>
